package obiecte;

import javax.media.opengl.GL2;

import main.TextureHandler;

public class Background {
	
	private TextureHandler texture;
	
	public Background(TextureHandler tex){
		texture = tex;
	}
	
	public void draw(GL2 gl) 
	{
		gl.glMatrixMode(GL2.GL_PROJECTION);
		gl.glPushMatrix();
		gl.glOrtho(0, 1, 0, 1, 0, 1);
		
		gl.glMatrixMode(GL2.GL_MODELVIEW);
		gl.glPushMatrix();
		gl.glLoadIdentity();
		
		// No depth buffer writes for background.
		gl.glDepthMask( false );
		
		texture.bind();
		texture.enable();
		//gl.glBindTexture( GL2.GL_TEXTURE_2D, textureId[4] );
		gl.glBegin( GL2.GL_QUADS ); 
		{
			gl.glTexCoord2f( 0f, 0f );
			gl.glVertex2f( 0, 0 );
			gl.glTexCoord2f( 0f, 2f );
			gl.glVertex2f( 0, 2f );
			gl.glTexCoord2f( 2f, 2f );
			gl.glVertex2f( 2f, 0.5f );
			gl.glTexCoord2f( 2f, 0f );
			gl.glVertex2f( 2f, 0 );
		} 
		gl.glEnd();
		
		gl.glDepthMask( true );
		
		gl.glPopMatrix();
		gl.glMatrixMode(GL2.GL_PROJECTION);
		gl.glPopMatrix();
		gl.glMatrixMode(GL2.GL_MODELVIEW);
		texture.disable();
	}

}
